package com.eol.admin.modules.business.dataCenter;

import com.eol.common.constants.BaseCommonConstants;
import com.eol.entity.po.customer.ZCustomerMessage;
import com.eol.mapper.config.tkMybatis.TableData;
import com.eol.service.customer.ZCustomerMessageService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: liulinhui
 * Date: 2020/6/4
 * Time: 12:45 PM
 * Description: CustomerController
 */
@RestController
@RequestMapping("api/customer")
public class CustomerController {

    @Resource
    private ZCustomerMessageService zCustomerMessageService;

    @RequestMapping
    public ResponseEntity<Object> list(
            @RequestParam(value = "page", defaultValue = BaseCommonConstants.PAGE_HELP_PAGE) Integer page,
            @RequestParam(value = "size", defaultValue = BaseCommonConstants.PAGE_HELP_LIMIT) Integer limit,
            @RequestParam(value = "startTime", required = false) Timestamp startTime,
            @RequestParam(value = "endTime", required = false) Timestamp endTime,
            @RequestParam(value = "phone", required = false) String phone,
            @RequestParam(value = "email", required = false) String email) {
        PageHelper.startPage(page + 1, limit);
        List<ZCustomerMessage> list = zCustomerMessageService.selectByQuery(ZCustomerMessage.builder()
                .phone(phone)
                .email(email)
                .startTime(startTime)
                .endTime(endTime)
                .build());
        PageInfo<ZCustomerMessage> pageInfo = new PageInfo<>(list);
        TableData<ZCustomerMessage> tableData = new TableData<>(pageInfo.getTotal(), list);
        PageHelper.clearPage();
        return new ResponseEntity<>(tableData, HttpStatus.OK);
    }
}
